package com.bbh.plugin.single.privilege.core.service;


import com.bbh.plugin.single.privilege.core.entity.AccountApp;
import com.bbh.plugin.single.privilege.core.repository.AccountAppMapper;
import com.bbh.plugin.single.privilege.core.vo.AccountAppVo;
import com.bbh.plugin.single.privilege.core.vo.AppVo;
import com.bbh.common.base.service.BaseService;
import com.bbh.common.domain.Condition;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service
@Transactional
public class AccountAppService extends BaseService<AccountApp, String> {
    @Autowired
    private AccountAppMapper accountAppMapper;

    /**
     * @param params
     * @return
     */
    public List<AppVo> findAccountAppCodeList(Map<String, Object> params) {
        List<AppVo> list = accountAppMapper.findAccountAppCodeList(params);
        return list;
    }

    /**
     * 查询账号授权系统
     *
     * @return
     */
    public List<AccountAppVo> findAccountAppList(String accountId) {
        Condition condition = new Condition(true);
        condition.put("accountId", accountId);
        List<AccountAppVo> list = accountAppMapper.findAccountAppList(condition);
        return list;
    }

    /**
     * 查询账号授权系统
     *
     * @return
     */
    public List<String> findAccountAppCodeList(String accountId) {
        List<String> codeList = new ArrayList<>();
        Condition condition = new Condition(true);
        condition.put("accountId", accountId);
        List<AccountAppVo> list = accountAppMapper.findAccountAppList(condition);
        if (CollectionUtils.isNotEmpty(list)) {
            for (AccountAppVo vo : list) {
                codeList.add(vo.getAppCode());
            }
        }
        return codeList;
    }

}
